let express = require('express');

let userBusiness = require('../business/user');
let loginBusiness = require('../business/login');
let logoutBusiness = require('../business/logout');

let router = module.exports = express.Router();

/**
 * param userId
 */
let userIdPath = '/:userId([0-9a-fA-F]{24})';
router.param('userId', userBusiness.param);

/**
 * login
 */
// login check input
router.post('/login', loginBusiness.checkInput);
// login check login exist
router.post('/login', loginBusiness.checkUserExist);
// login compare password
router.post('/login', loginBusiness.comparePassword);
// login
router.post('/login', loginBusiness.suc);

/**
 * logout
 */
router.post('/logout', logoutBusiness.suc);

/**
 * add user, only admin can add an user.
 */
// check input
router.post('/', userBusiness.addCheckInput);
// check authorization
router.post('/', userBusiness.checkAuthorization);
// check cellphone
router.post('/', userBusiness.addCheckCellphone);
// check nickname
router.post('/', userBusiness.addCheckNickname);
// check email
router.post('/', userBusiness.addCheckEmail);
// suc
router.post('/', userBusiness.addSuc);

/**
 * delete user
 */
// check exist
router.delete(userIdPath, userBusiness.checkExist);
// check delete
router.delete(userIdPath, userBusiness.checkDelete);
// suc
router.delete(userIdPath, userBusiness.deleteSuc);

/**
 * update user
 */
// check authorization
router.put(userIdPath, userBusiness.checkAuthorization);
// check exist
router.put(userIdPath, userBusiness.checkExist);
// check delete
router.put(userIdPath, userBusiness.checkDelete);
// check nickname
router.put(userIdPath, userBusiness.updateCheckNicknameDuplicate);
// check email
router.put(userIdPath, userBusiness.updateCheckEmailDuplicate);
// update suc
router.put(userIdPath, userBusiness.updateSuc);

/**
 * get one user
 */
// get user
router.get(userIdPath, userBusiness.checkExist);
// check delete
router.get(userIdPath, userBusiness.checkDelete);
// get suc
router.get(userIdPath, userBusiness.getSuc);

/**
 * list user
 */
// user list
router.get('/', userBusiness.list);